<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<script type="text/javascript">
    var editor = new baidu.editor.ui.Editor();
    $(function() {
//        显示查询信息（含分页、排序、筛选等功能）
        $('#admin_room_datagrid').datagrid({
            url : '${pageContext.request.contextPath}/roomController/datagrid.action',
            fit : true,
            fitColumns : true,
            border : false,
            pagination : true,
            idField : 'id',
            pageSize : 10,
            pageList : [ 10, 20, 30, 40, 50 ],
            sortName : 'id',
            sortOrder : 'desc',
            checkOnSelect : false,
            selectOnCheck : false,
            nowrap : false,
            frozenColumns : [ [ {
                field : 'id',title : '编号',checkbox : true},{
                field : 'name',title : '房名（房型）',sortable : true
        }]],
            columns:[[{
                field : 'pic',title : '房间图片',formatter : function(value, row, index) {
                    return formatString("<img  src='http://www.cq666666.cn/"+ value + "' width='60' height='40' onclick=\"djImg('"+value+"')\" />");
                } },{
                field : 'deptName',title : '所属单位',sortable : true,},{
                field : 'units',title : '房间单位',sortable : true,},{
                field : 'price',title : '非会员价',sortable : true,},{
                field : 'jdPrice',title : '基本卡（价格）'},{
                field : 'whPrice',title : '维护卡（价格）'},{
                field : 'cjPrice',title : '促进卡（价格）'},{
                field : 'payTypeName',title : '支付方式'},{
                field : 'comment',title : '房间说明'},{
                field : 'createTime',title : '创建时间'},{
                field : 'createName',title : '创建者'},{
                field : 'checkTime',title : '修改时间'},{
                field : 'checkName',title : '修改者'},{
                field : 'personNumber',title : '入住人数'},{

                field : 'action1',title : '查看详情/修改',align : 'center',
                formatter : function(value, row, index) {
                    return formatString('<img onclick="admin_currency_editFun(\'{0}\');" src="{1}"/>&nbsp;<img onclick="admin_currency_removeFun(\'{2}\');" src="{3}"/>', row.id, '${pageContext.request.contextPath}/style/images/extjs_icons/pencil.png', row.id, '${pageContext.request.contextPath}/style/images/extjs_icons/cancel.png');
                }
            }]],
            toolbar : [ {
                text : '添加内容',iconCls : 'icon-add',handler : function() {
                    admin_currency_appendFun();
                }
            }]
        });


    });

    function djImg(val){
        $("#div_img").css("display","block")
        $("#div_img").find("img").attr("src","http://www.cq666666.cn/"+val+"")
        $("#div_img").dialog({
            title:"图片",
        })
    }
    function admin_currency_searchFun() {
        $('#admin_room_datagrid').datagrid('load', serializeObject($('#admin_currency_searchForm')));
    }

    function admin_currency_cleanFun() {
        $('#admin_currency_searchForm input').val('');
        $('#admin_room_datagrid').datagrid('load', {});
    }

    function admin_currency_editFun(id) {
        $('#admin_room_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
        $('<div/>').dialog({
            href : '${pageContext.request.contextPath}/admin/room_edit.jsp',
            width : 800,
            height : 600,
            modal : true,
            title : '信息修改',
            buttons : [ {
                text : '保存',
                iconCls : 'icon-edit',
                handler : function() {
                    var d = $(this).closest('.window-body');
                    $('#admin_roomEdit_editForm').form('submit', {
                        url : '${pageContext.request.contextPath}/roomController/edit_currency.action',
                        success : function(result) {
                            try {
                                var r = $.parseJSON(result);
                                if (r.success) {
                                    $('#admin_room_datagrid').datagrid('reload');
                                    d.dialog('destroy');
                                }
                                $.messager.show({
                                    title : '提示',
                                    msg : r.msg
                                });
                            } catch (e) {
                                $.messager.alert('提示', result);
                            }
                        }
                    });
                }
            } ],
            onClose : function() {
                $(this).dialog('destroy');
            },
            onLoad : function() {
                var index = $('#admin_room_datagrid').datagrid('getRowIndex', id);
                var rows = $('#admin_room_datagrid').datagrid('getRows');
                var o = rows[index];
                $('#admin_roomEdit_editForm').form('load', o);
            }
        });
    }


    function admin_currency_appendFun() {
        $('#admin_room_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
        $('<div/>').dialog({
            href : '${pageContext.request.contextPath}/admin/room_add.jsp',
            width : 800,
            height :600,
            modal : true,
            title : '信息添加',
            buttons : [ {
                text : '保存',
                iconCls : 'icon-add',
                handler : function() {
                    var d = $(this).closest('.window-body');
                    $('#admin_currencyAdd_addForm').form('submit', {
                        url : '${pageContext.request.contextPath}/roomController/add_currency.action',
                        success : function(result) {
                            try {
                                var r = $.parseJSON(result);
                                if (r.success) {
                                    $('#admin_room_datagrid').datagrid('load',{sort : 'createTime', order : 'desc'});
                                    d.dialog('destroy');
                                }
                                $.messager.show({
                                    title : '提示',
                                    msg : r.msg
                                });
                            } catch (e) {
                                $.messager.alert('提示', result);
                            }
                        }
                    });
                }
            } ],
            onClose : function() {
                $(this).dialog('destroy');
            }
        });
    }
    function admin_currency_removeFun() {
        var rows = $('#admin_room_datagrid').datagrid('getChecked');
        var ids = [];
        if (rows.length > 0) {
            $.messager.confirm('确认', '您是否要删除当前选中的项目？', function(r) {
                if (r) {
                    var currentUserId = '${sessionInfo.userId}';/*当前登录用户的ID*/
                    var flag = false;
                    for ( var i = 0; i < rows.length; i++) {
                        if (currentUserId != rows[i].id) {
                            ids.push(rows[i].id);
                        } else {
                            flag = true;
                        }
                    }
                    $.ajax({
                        url : '${pageContext.request.contextPath}/roomController/remove_currency.action',
                        data : {ids : ids.join(',')  },
                        dataType : 'json',
                        success : function(result) {
                            if (result.success) {
                                $('#admin_room_datagrid').datagrid('load');
                                $('#admin_room_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
                            }
                            if (flag) {
                                $.messager.show({
                                    title : '提示',
                                    msg : '不可以删除自己！'
                                });
                            } else {
                                $.messager.show({
                                    title : '提示',
                                    msg : result.msg
                                });
                            }
                        }
                    });
                }
            });
        } else {
            $.messager.show({
                title : '提示',
                msg : '请勾选要删除的记录！'
            });
        }
    }
</script>
<div class="easyui-layout" data-options="fit : true,border : false">
    <div data-options="region:'north',title:'查询条件',border:false" style="height:200px" align="center">
        <form id="admin_currency_searchForm">
            <table class="tableForm">
                <tr>
                    <th style="width: 170px;">房间名称</th>
                    <td><input class="easyui-validatebox" name="name"></td>
                </tr>
                <tr>
                    <th style="width: 170px;">房间单位</th>
                    <td>
                        <input type="text" class="easyui-combotree" name="deptId" data-options="url:'${pageContext.request.contextPath}/infoController/find_info.action?ids=02,03,04,05'" id="dept_type_1" style="width: 230px;">
                        <img src="${pageContext.request.contextPath}/style/images/extjs_icons/cut_red.png" onclick="$('#dept_type_1').combotree('clear');" />
                    </td>
                </tr>
            </table>
            <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="admin_currency_searchFun();">过滤</a> <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true" onclick="admin_currency_cleanFun();">取消过滤</a>
        </form>
    </div>
    <div data-options="region:'center',border:false">
        <table id="admin_room_datagrid"></table>
    </div>
</div>
<div  id="div_img"><img src="" style="width: 100%;height: 90%;"></div>